package com.wlgc.mapper;

import com.wlgc.entity.Assigment.Student_Assigment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AssignmentMapper {
@Results({
        @Result(column = "sid",property = "sid"),
        @Result(column = "aid",property = "aid"),
        @Result(column = "cid",property = "cid"),
        @Result(column = "studentName",property = "studentName"),
        @Result(column = "isFinish",property = "isFinish"),
        @Result(column = "assignmentName",property ="assignmentName"),
        @Result(column = "courseName",property = "courseName"),
        @Result(column = "detail",property = "detail")


})
    @Select("select s1.sid as sid,s1.aid as aid ,c1.cid as cid,u1.name as studentName,s1.isFinish as isFinish,a1.name as assignmentName," +
            "a1.detail as detail,c1.name as courseName from sa as s1,assignment as a1,course as c1,user as u1 where u1.id=#{sid} and u1.id=s1.sid " +
            " and s1.isFinish='未完成' and a1.aid=s1.aid and c1.cid=a1.cid")
   List<Student_Assigment> get_UnFinish_Assigment(@Param("sid")int sid );
    @Results({
            @Result(column = "sid",property = "sid"),
            @Result(column = "aid",property = "aid"),
            @Result(column = "cid",property = "cid"),
            @Result(column = "studentName",property = "studentName"),
            @Result(column = "isFinish",property = "isFinish"),
            @Result(column = "assignmentName",property ="assignmentName"),
            @Result(column = "courseName",property = "courseName"),
            @Result(column = "detail",property = "detail")


    })
    @Select("select s1.sid as sid,s1.aid as aid ,c1.cid as cid,u1.name as studentName,s1.isFinish as isFinish,a1.name as assignmentName," +
            "a1.detail as detail ,c1.name as courseName from sa as s1,assignment as a1,course as c1,user as u1 where u1.id=#{sid} and u1.id=s1.sid " +
            "and s1.isFinish='完成' and a1.aid=s1.aid and c1.cid=a1.cid")
    List<Student_Assigment> get_Finish_Assigment(@Param("sid")int sid );
    @Results({
            @Result(column = "sid",property = "sid"),
            @Result(column = "aid",property = "aid"),
            @Result(column = "cid",property = "cid"),
            @Result(column = "studentName",property = "studentName"),
            @Result(column = "isFinish",property = "isFinish"),
            @Result(column = "assignmentName",property ="assignmentName"),
            @Result(column = "courseName",property = "courseName"),
            @Result(column = "detail",property = "detail")
    })







    @Select("select s1.sid as sid,s1.aid as aid ,c1.cid as cid,u1.name as studentName,s1.isFinish as isFinish,a1.name as assignmentName," +
            "a1.detail as detail ,c1.name as courseName from sa as s1,assignment as a1,course as c1,user as u1 where u1.id=#{sid} and u1.id=s1.sid " +
            "and a1.aid=s1.aid and c1.cid=a1.cid")
    List<Student_Assigment> get_All_Assigment(@Param("sid")int sid );
    @Update("update sa set isFinish ='完成' where sid=#{sid} and aid=#{aid}")
     void finishAssignment(@Param("sid") int sid,@Param("aid") int aid);

    @Select("select detail from assignment where aid =#{aid}")
    String getDetail(@Param("aid")int aid);
    @Results({
            @Result(column = "id",property = "sid"),
            @Result(column = "name",property = "studentName"),
    })
    @Select("select distinct s1.id,s1.username from user as s1 where s1.Cno=#{Cno} and s1.id in(select distinct sid from sa where isFinish='未完成')")
    List<Student_Assigment> getClassStudent_UF(@Param("Cno")int cno);




 //获取未完成作业的学生
 @Results({
         @Result(column = "id",property = "sid"),
         @Result(column = "name",property = "studentName"),
         @Result(column = "未完成",property ="isFinish" ),
         @Result(column = "courseName",property = "courseName")
 })
    @Select("select u1.id,u1.name,'未完成',c1.name as courseName from user as u1,course as c1 where c1.cid=#{cid} and u1.Cno=#{Cno} and u1.id  in " +
            " (SELECT DISTINCT sid FROM sa where isFinish='未完成' and aid in(SELECT aid FROM assignment where cid=c1.cid)); ")
    List<Student_Assigment> getClass_Course_Student_UF(@Param("Cno")int cno,@Param("cid") int cid);

 //获取已完成作业的学生
 @Results({
         @Result(column = "id",property = "sid"),
         @Result(column = "name",property = "studentName"),
         @Result(column = "完成",property ="isFinish" ),
         @Result(column = "courseName",property = "courseName")
 })
 @Select("select u1.id,u1.name,'完成',c1.name as courseName from user as u1,course as c1 where c1.cid=#{cid} and u1.Cno=#{Cno} and u1.id not in " +
         " (SELECT DISTINCT sid FROM sa where isFinish='未完成' and aid in(SELECT aid FROM assignment where cid=c1.cid)); ")
 List<Student_Assigment> getClass_Course_Student_F(@Param("Cno")int cno,@Param("cid") int cid);
}
